const { app, BrowserWindow, Menu, contextBridge, ipcMain, ipcRenderer } = require('electron')
const path = require('path')
    // Menu.setApplicationMenu(null)

app.whenReady().then(() => {
    let win = new BrowserWindow({
        width: 422,
        height: 342,
        resizable: false,
        frame: false,
        webPreferences: {
            preload: path.join(__dirname, 'preload.js'),
            nodeIntegration: true,
            contextIsolation: true
        }
    })
    win.loadFile('./login.html')
    ipcMain.on("closeWin", (event, date) => {
            win.close()
        })
        /* 监听登录事件 */
    ipcMain.on("sendMessage", (event, data) => {
        let port = data
        let client = new BrowserWindow({
            width: 310,
            height: 700,
            resizable: false,
            frame: false,
            webPreferences: {
                preload: path.join(__dirname, 'client.js'),
                nodeIntegration: true,
                contextIsolation: true
            }
        })
        win.close()
        client.loadFile('./client.html')
        ipcMain.on("closeClient", (event, data) => {
            client.close()
        })
        ipcMain.on("openTalk", (event, data) => {
            let talk = new BrowserWindow({
                    width: 620,
                    height: 680,
                    resizable: false,
                    frame: false,
                    webPreferences: {
                        preload: path.join(__dirname, 'talk.js'),
                        nodeIntegration: true,
                        contextIsolation: true
                    }
                })
                // client.
            talk.loadFile('./talk.html')
            ipcMain.on("closeTalk", (event, data) => {
                talk.close()
            })
        })
    })

})

app.on('window-all-closed', function() {
    if (process.platform !== 'darwin') {
        app.quit()
    }
})

try {
    require('electron-reloader')(module, {});
} catch (_) {}